﻿namespace BPM.Web.Shared.Extensions;

public static class BooleanExtensions
{
    /// <summary>
    /// 值为True时执行
    /// </summary>
    /// <param name="value"></param>
    /// <param name="func"></param>
    /// <returns></returns>
    public static bool TrueFor(this bool value, Func<bool> func)
        => value ? func() : value;

    /// <summary>
    /// 值为True时执行
    /// </summary>
    /// <param name="value"></param>
    /// <param name="func"></param>
    /// <returns></returns>
    public static Task<TResult> TrueFor<TResult>(this bool value, Func<Task<TResult>> func)
        where TResult : class, new()
        => value ? func() : new TResult().AsTask();

    /// <summary>
    /// 值为True时执行
    /// </summary>
    /// <param name="value"></param>
    /// <param name="func"></param>
    /// <returns></returns>
    public static Task<bool> TrueFor(this bool value, Func<Task<bool>> func)
        => value ? func() : value.AsTask();
}

